package com.studentcontrol;

import com.dao.StudentDao;
import com.model.Student;
import org.apache.struts2.interceptor.SessionAware;

import javax.naming.NamingException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Map;

/**
 * @author :wn
 * @program : 学生信息管理系统
 * @descript : 查看所有
 * @create :2020-11-13 23:01
 */

public class ViewAllInterAction implements SessionAware {
    public String viewAll() throws SQLException, NamingException {
        ArrayList<Student> list = new ArrayList();
        ResultSet rs = new StudentDao().quaryMethod();
        while (rs.next()) {
            Student student = new Student();
            student.setName(rs.getString("name"));
            student.setAge(rs.getString("age"));
            student.setSex(rs.getString("sex"));
            student.setDept(rs.getString("sdept"));
            list.add(student);
        }
        Statement st = rs.getStatement();
        Connection con = st.getConnection();
        con.close();
        st.close();
        rs.close();
        session.put("studentList", list);
        return "success";
    }
    Map<String ,Object>session;


    @Override
    public void setSession(Map<String, Object> map) {
        this.session=map;
    }
}
